package com.cssw.fyzb.busi.api.video;

import com.cssw.fyzb.busi.service.video.VideoService;
import com.cssw.fyzb.core.model.vo.video.FoundVideoByPhpVo;
import com.cssw.fyzb.core.model.vo.video.ScityVideoByPhpVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 查询 同城 视频列表
 *
 * @author YangYiQun
 */
@Function(description = "查询 同城 视频列表", parameters = {
        @Parameter(name = "city", type = Type.Integer, description = "城市", required = true),
        @Parameter(name = "lat", type = Type.Integer, description = "维度", required = true),
        @Parameter(name = "lng", type = Type.Integer, description = "经度", required = true),
        @Parameter(name = "pageNumber", type = Type.Integer, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.Integer, description = "页大小", required = true),
})
@Component
public class ListScityByPhpVideo implements Action {

    @Autowired
    private VideoService videoService;

    private static final Logger logger = LoggerFactory.getLogger(ListScityByPhpVideo.class);

    @Override
    public Response execute(Request request) throws Exception {
        String lat = request.getString("lat");
        String city = request.getString("city");
        String lng = request.getString("lng");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        try {
            Page<ScityVideoByPhpVo> page = videoService.pageScityByPhp(city, lat, lng, pageNumber, pageSize);
            return Response.success().put("list", page.getList()).put("total", page.getTotalPage()).put("count", page.getTotalRow());
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
